<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active {
            color: red
        }
    </style>

</head>

<div id="app">
    {{msg}}===={{total(111)}}
    <hr> 姓名:<input v-model="name" /> 分数:
    <input v-model.number="score" /> <button @click="add">添加</button>
    <ul>
        <li v-for="item in list" :key="item.id">{{item.id}}==={{item.name}}==={{item.subject}}===
            <span :class="{active:item.score<60}">{{item.score}}</span>===
            <button @click="del(item.id)">删除</button>
        </li>
    </ul>

    自动求班级平均分:==={{avg}}




</div>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.min.js"></script>
<script>
    const vu = new Vue({
        el: "#app",
        data: {
            msg: 'hello vue',
            list: [{
                id: 1,
                name: 'jack',
                subject: '数学',
                score: 70,

            }, {
                id: 1,
                name: 'jack',
                subject: '数学',
                score: 80,

            }, {
                id: 1,
                name: 'jack',
                subject: '数学',
                score: 90,

            }],
            name: '',
            score: '',



        },
        methods: {
            add() {
                this.list.push({
                    id: Date.now(), //获取现在的时间戳,id唯一值
                    name: this.name,
                    subject: '数学',
                    score: this.score,
                })
            },
            del(x) {
                this.list = this.list.filter(ele => ele.id !== x)

            }

        },
        computed: {
            avg() {
                return this.list.reduce((sum, item) => sum + item.score, 0) / this.list.length
            },
            total() {
                //如何使computed实现传参
                return function(str) {
                    return this.name + '** ** **' + str

                }

            }

        }
    })
</script>






</body>

</html>